package domain

import "time"

type Article struct {
	Id int64
	Title string
	Content string
	Author Author
	CreateTime time.Time
	UpdateTime time.Time
	Status     ArticleStatus
}

type Author struct {
	Id int64
	Name string
}

func (a Article) Abstract() string {
	// 取前几句，考虑中文问题
	cs := []rune(a.Content)
	if len(cs)<100 {
		return a.Content
	}
	return string(cs[:100])

}

const (
	ArticleStatusUnknown = iota
	ArticleStatusUnpublished
	ArticleStatusPublished
	ArticleStatusPrivate
)

type ArticleStatus uint8

func (s ArticleStatus) ToUint8() uint8 {
	return uint8(s)
}

func (s ArticleStatus) Valid() bool {
	return s.ToUint8()>0
}

func (s ArticleStatus) NonPublished() bool {
	return s!=ArticleStatusPublished
}
